import { getCurrentInstance, inject, onMounted, ref } from 'vue';
import { objectAny } from '../../../options/base';
import uqrcodePlugin from '../../plugins/uqrcode/uqrcode.vue'
import { turnOrderScanCode } from '../../utils';

export default {
    components: {
        uqrcodePlugin
    },
    props:{
        showScanBtn:{
            type:Boolean,
            default:true
        }
    },
    setup(props:any) {
        console.log(`------- rider-turn-order ----`)
        const locaUserInfo = uniCloud.getCurrentUserInfo()

        const qrCodeCont = encodeURIComponent(JSON.stringify({uid:locaUserInfo.uid}));

        const turnOrderQrcodeRef = inject(`turnOrderQrcodeRef`);
        const riderCurrentPopupItData = inject(`riderCurrentPopupItData`);
        const riderCurrentPopupItDragBtnStyle = inject(`riderCurrentPopupItDragBtnStyle`);
        const closePopup = inject(`closePopup`);
        const parentReload = inject(`parentReload`);
        
        async function comTurnOrderScanCode(){
            const { _id,order_id}= (riderCurrentPopupItData as objectAny).value
            const result =await turnOrderScanCode(_id,order_id)
            if(result){
                (closePopup as Function)(1)
                parentReload&&(parentReload as Function)()
            }
        }

        return {
            qrCodeCont,
            turnOrderQrcodeRef,
            riderCurrentPopupItData,
            riderCurrentPopupItDragBtnStyle,
            comTurnOrderScanCode
        }
    }   
}